program FiveProcedures;

{$APPTYPE CONSOLE}

uses
  SysUtils;

type
  pelement = ^element;
  element = record
    value : integer;
    next : pelement;
  end;

  procedure AddToEnd (var head : pelement;
  num : integer  );
  var
    current : pelement;
  begin
    if (head <> nil) then
      current := head;
      while (current^.next <> nil) do
      begin
        current := current^.next;
        new (current^.next);
        current^.next^.value := num;
        current^.next^.next := nil;
      end else begin
      AddToBegin(head, num);
    end;


  procedure printList (head : pelement);
  var
     current := pelement;
  begin
   current := head;
   while (current <> nil) do
    begin
      writeln(current^.value);
      current = current^.next;
    end;
  end;

  procedure DisposeFromBegin (head : pelement);
  var
   temp : pelement;
  begin
    temp := head^.next;
    dispose (head);
    head := temp;
  end;

  procedure AddToBegin (var head : pelement;
  num : integer);
  var
     tmp : integer;
  begin
    tmp := head;
    new(head);
    head^.value := num;
    head^.next := tmp;
 end;   

  procedure DisposeFromEnd (head : pelement);
  var
    current : pelement;
  begin
  if (head <> nil) then
  begin
  current := head;
  while (current^.next^.next <> nil) do
  current := current^.next;
  current^.next := nil;
  end;


begin

end.
